<?php

namespace app\home\model;
use think\Model;
use think\Db;

class IndexModel extends Model
{

    /**
     * [getAllArticle 获取文章总数]
     * @author [Boot.Z] [852952656@qq.com]
     */
	public function getByCount($map)
	{
		return Db::name('article')
            ->where($map)
            ->count();
	}


	
    /**
     * [getAllArticle 获取全部文章]
     * @author [Boot.Z] [852952656@qq.com]
     */
    public function getArticleByWhere($map, $nowpage, $limits)
    {
        return Db::name('article')
            ->field('think_article.*,name')
            ->join('think_article_cate', 'think_article.cate_id = think_article_cate.id')
            ->where($map)
            ->page($nowpage, $limits)
            ->order('id desc')
            ->select();
    }

    /**
     * getTenNewArticle [ 取出当前cate_id 的新闻 ]
     * @author [Boot.Z] [852952656@qq.com]
     * @return false|\PDOStatement|string|\think\Collection
     * @param $id
     */
    public function getTenNewArticle($id)
    {
        return Db::name('article')
                ->field('id,title,create_time,photo,is_tui')
                ->where(array('cate_id' => $id))
                ->where('status > 0')
                ->limit(10)
                ->order('id desc')
                ->select();
    }

}